package com.tbit.uqbike.client.controller;

import com.tbit.uqbike.client.constant.ResponseCode;
import com.tbit.uqbike.client.exception.BaseException;
import com.tbit.uqbike.client.pojo.newEntity.AccountGif;
import com.tbit.uqbike.client.service.AccountGifService;
import com.tbit.uqbike.client.util.Assert;
import com.tbit.uqbike.client.util.OutputUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: chen
 * @Description: 区域GIF图片配置
 * @Date: 创建于 13:57 2023/5/24
 */
@Controller
@RequestMapping("/accountGif")
public class AccountGifController {

    @Autowired
    private AccountGifService accountGifService;

    /**
     * 通过车辆编号获取
     *
     * @param userCode 车辆编号
     * @param session
     * @param request
     * @param response
     */
    @RequestMapping("/getByAccountId")
    public void getByAccountId(String userCode, HttpSession session,
                               HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> map = new HashMap<String, Object>();

        try {

            Assert.notNull(userCode, "-30006", "车辆编号不能为空");

            List<AccountGif> accountGif = accountGifService.getByAccountId(userCode);

            map.put(ResponseCode.RET, ResponseCode.SUCC);
            map.put(ResponseCode.DATA, accountGif);
        } catch (BaseException e) {
            ResponseCode.printException(map, e, request);
        }

        OutputUtil.renderText(request, response, map);
    }
}
